import { defHttp } from '/@/common/util/axios';
import { useMessage } from '/@/hooks/web/useMessage';

const { createConfirm } = useMessage();

enum Api {
  list = '/emp/hubTeamWork/getPage',
  save = '/emp/hubTeamWork/add',
  edit = '/emp/hubTeamWork/edit',
  deleteOne = '/emp/hubTeamWork/delete',
  deleteBatch = '/emp/hubTeamWork/deleteBatch',
  importExcel = '/emp/hubTeamWork/importExcel',
  exportXls = '/emp/hubTeamWork/exportXls',
  batchUpdate = '/emp/hubTeamWork/updateBatch', //批量新增
  treeList = '/emp/hubTeamWorkType/getList', //获取树形数据
  dictDataLiat = '/emp/common/getDictDataLiat', // 统计频次下拉框
  importHistory = '/emp/hubTeamWork/importHistory', //历史指标库移入
  typicalList = '/emp/hubTeamWork1Type/getList', // 典型库树列表
  typicalPageList = '/emp/hubTeamWork1/getList',
  importModelHistory = '/emp/hubTeamWork/importModelHistory', //典型库移入
}

export const typicalPageList = (params) => defHttp.get({ url: Api.typicalPageList, params });

export const typicalList = () => defHttp.get({ url: Api.typicalList });

export const importModelHistory = (params) => defHttp.post({ url: Api.importModelHistory, params });

export const importHistory = (params) => defHttp.post({ url: Api.importHistory, params });
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 统计频次下拉框接口
 * @param params
 */
export const getDictDataLiat = () => {
  const params = {
    type: 'work_item_count',
  };
  return new Promise((resolve) => {
    defHttp.get({ url: Api.dictDataLiat, params }).then((res) => {
      resolve(res);
    });
  });
};

// 树形列表接口
export const treeList = (params) => defHttp.get({ url: Api.treeList, params });

/**
 *
 *
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};

/**
 * 批量更新
 * @param params
 */
export const updateList = (params) => {
  const url = Api.batchUpdate;
  return defHttp.post({ url: url, params });
};
